<template>
  <view v-if="list.length > 0" class="waterfall-container">
    <view v-for="(col, i) in columns" :key="i" class="column">
      <view v-for="item in col" :key="item.id" class="item">
        <slot :item="item" name="default">
          <navigator :url="'/pagesA/u/u?uid=' + item.uid" class="a">
            <view class="em">
              <image :src="item.photo_m" class="m" mode="aspectFill"></image>
              <view :style="'background:url(' + nikbg + ') repeat-x;background-size:100% 100%;'" class="nik">
                <text class="span">{{ item.nickname }}</text>
              </view>
              <image v-if="!globalUtils.empty(item.vipj)" :src="item.vipj" class="vipj" mode="widthFix"></image>
            </view>
            <view class="uinfo">
              <view class="data">
                <view class="span">
                  <text class="font">{{ item.ageheighedu }}</text>
                </view>
                <view class="span">
                  <text v-if="!globalUtils.empty(item.areatitle)" class="b ico">{{ item.areatitle }}</text>
                  <text v-if="!globalUtils.empty(item.job)" class="b">{{ item.job }}</text>
                </view>
              </view>
            </view>
            <image v-if="!globalUtils.empty(item.rzj)" :src="item.rzj" class="rzj" mode="aspectFill"></image>
          </navigator>
        </slot>
      </view>
    </view>
  </view>
</template>

<script>

import globalUtils from "../../res/www.a9a.cn";

export default {
  name: "Member",
  computed: {
    globalUtils() {
      return globalUtils
    }
  },
  props: {
    list: Array,
    colNum: {
      type: Number,
      default: 2
    },
    index: {
      type: Number,
      default: 1
    },
    nikbg: {
      type: String,
      default: ""
    }

  },
  data() {
    return {
      columns: Array(this.colNum).fill().map(() => []),
      heights: Array(this.colNum).fill(0),
      loginBoxFlag: false,
    }
  },
  watch: {
    list: {
      handler() {
        this.distributeItems()
      },
      immediate: true
    }
  },
  methods: {
    distributeItems() {
      this.columns = Array(this.colNum).fill().map(() => [])
      this.heights = Array(this.colNum).fill(0)
      this.list.forEach(item => {
        const minIndex = this.heights.indexOf(Math.min(...this.heights))
        this.columns[minIndex].push(item)
        this.heights[minIndex] += item.height || 300
      })
    },
    updateLayout() {
      this.$nextTick(this.distributeItems)
    }
  }
}
</script>

<style lang="scss" scoped>
.corBg {
  color: #f34dc7;
}

.corMale {
  color: #56c2f4;
}

.waterfall-container {
  display: flex;
  justify-content: space-between;

  .column {
    flex: 1;
    min-width: 0;
    margin: 0 10rpx;
  }

  .item {
    margin-bottom: 10px;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

    .a {
      padding: 0;
      width: 100%;
    }

    .a,
    .a .em {
      display: block;
      position: relative;
    }

    .a .em {
      background-color: #fff;
      border-radius: 10rpx 10rpx 0 0;
      box-sizing: border-box;
      width: 100%;
    }

    .a .em image.m {
      border-radius: 10rpx 10rpx 0 0;
      display: block;
      object-fit: cover;
      width: 100%;
    }

    .a .em .nik {
      bottom: 0;
      color: #fff;
      font-size: 30rpx;
      height: 100rpx;
      left: 0;
      line-height: 120rpx;
      position: absolute;
      text-align: center;
      width: 100%;
    }

    .a .em .nik .span {
      display: inline-block;
      vertical-align: middle;
    }

    .a .em .nik image {
      margin-left: 6rpx;
      vertical-align: middle;
    }

    .a .em .nik .span {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 82%;
    }

    .a .em .vipj {
      display: block;
      position: absolute;
      right: 14rpx;
      top: 14rpx;
      width: 100rpx;
    }

    .a .uinfo {
      background-color: #fff;
      border-radius: 0 0 10rpx 10rpx;
      border-top: 0;
      box-sizing: border-box;
      margin: 0 auto;
      padding-bottom: 1rpx;
      text-align: left;
      width: 100%;
    }

    .a .uinfo .data {
      font-size: 27rpx;
      line-height: 40rpx;
      margin: 0 auto 16rpx;
      padding: 20rpx 0 0;
      text-align: center;
    }

    .a .uinfo .data .span .font,
    .a .uinfo .data .span image {
      display: inline-block;
      vertical-align: middle;
    }

    .a .uinfo .data .span {
      display: block;
      width: 100%;
    }

    .a .uinfo .data .span .b {
      background-color: rgba(var(--rgbcolor), 0.1);
      border-radius: 6rpx;
      box-sizing: border-box;
      color: var(--color);
      display: inline-block;
      font-size: 24rpx;
      font-weight: 400;
      height: 44rpx;
      line-height: 44rpx;
      margin-right: 20rpx;
      margin-top: 12rpx;
      max-width: 50%;
      overflow: hidden;
      padding: 0 10rpx;
    }

    .a .uinfo .data .span .b:last-child {
      margin-right: 0;
    }

    .a .uinfo .data .ico {
      color: #49bef5;
      display: inline-block;
      margin-right: 4rpx;
    }

    .a .payrz {
      border-radius: 6rpx;
      line-height: 28rpx;
      position: absolute;
      right: 24rpx;
      top: 0;
      width: 30rpx;
    }

    .a .payrz .i {
      border-radius: 6rpx;
      display: block;
      margin: 10rpx 0;
      padding: 1rpx;
    }

    .a .rzj {
      display: block;
      height: 100rpx;
      left: -1%;
      position: absolute;
      top: -4rpx;
      width: 108rpx;
    }
  }
}


</style>
